function R=warshall(R0)
%
%GARP-website: http://www.revealedpreferences.org
%Aug 6, 2012

% We look for transitivities: if i R0 j and j R0 k then we note i R k 
%(i indirectly revealed preferred over j).
% Adapt R0-matrix such that element (i,j)=1 if i R j
T=size(R0,1);
R=R0;
for k=1:T
    for i=[1:k-1, k+1:T] % Iterate through all 'rows' except k
        if R(i,k)>0     % Only changes possible if (i,k) not 0
            for j=[1:k-1, k+1:T]
                if R(i,j)==0
                    R(i,j)=R(k,j);
                end % if
            end % for j
        end % if
    end % for i
end %for k